package com.runshu.runshuwulian.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.runshu.runshuwulian.R;
import com.runshu.runshuwulian.base.BaseActivity;
import com.runshu.runshuwulian.bean.MsgEventEntity;
import com.runshu.runshuwulian.ui.viewhelper.LoginViewHelper;
import com.runshu.runshuwulian.utils.StatusBarUtil;
import com.runshu.runshuwulian.utils.UtilSharedPreference;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.OnClick;

public class LoginActivity extends BaseActivity {

    @BindView(R.id.bt_wx_login)
    View mBtWxLogin;
    @BindView(R.id.bt_register)
    TextView mBtRegister;
    @BindView(R.id.bt_phone_login)
    TextView mBtPhoneLogin;
    @BindView(R.id.bt_checkbox)
    View bt_checkbox;
    @BindView(R.id.bt_agreement_fw)
    TextView mBtAgreementFw;
    @BindView(R.id.bt_agreement_ys)
    TextView mBtAgreementYs;

    LoginViewHelper helper;

    @Override
    protected int setContentViewResId() {
        return R.layout.act_login;
    }

    @Override
    protected void initView(@Nullable Bundle savedInstanceState) {
        helper = new LoginViewHelper( this );
        StatusBarUtil.StatusBarLightMode( this );
    }

    public void onLoginSuccess() {
        dissmissProgressDialog();
        startActivityByDefaultAnim( MainActivity.class );
        showShortToast( getResources().getString( R.string.dlcg ) );
        finish();
    }

    public void onLoginToBindDoctor() {
        dissmissProgressDialog();
//        showDefaultProgressDialog(  );
//        showShortToast( "去绑定医生" );
    }

    public void onLoginFailed(String msg) {
        dissmissProgressDialog();
        showShortToast( msg );
    }

    public void goBDSJAct(String openID, String unionID, String avatar, String nick) {
        dissmissProgressDialog();
//        Intent intent = new Intent( self(), BindPhoneActivity.class );
//        intent.putExtra( "type", 1 );
//        intent.putExtra( "unionid", unionID );
//        intent.putExtra( "openid", openID );
//        intent.putExtra( "avatar", avatar );
//        intent.putExtra( "nick", nick );
//        startActivityByDefaultAnim( intent );
    }


    @OnClick({R.id.bt_agreement_fw, R.id.bt_agreement_ys, R.id.bt_register, R.id.bt_phone_login, R.id.bt_wx_login, R.id.bt_checkbox})
    public void onViewClicked(View v) {
        Intent intent = new Intent();
        switch (v.getId()) {
            case R.id.bt_agreement_fw:
//                intent.setClass( this, AgreementActivity.class );
//                intent.putExtra( "type", 1 );
//                startActivityByAlphAnim( intent );
                break;
            case R.id.bt_agreement_ys:
//                intent.setClass( this, AgreementActivity.class );
//                intent.putExtra( "type", 2 );
//                startActivityByAlphAnim( intent );
                break;
            case R.id.bt_wx_login:
//                showDefaultProgressDialog( true );
//                if (!bt_checkbox.isSelected()) {
////                    showShortToast( getString( R.string.yonghuxieyiyinsizhengce ) );
//                    showFirstDialog();
//                    break;
//                }
                UtilSharedPreference.setIsFirst( self() );
                helper.loginWX( this );
//                selectArea();
                break;
            case R.id.bt_checkbox:
                bt_checkbox.setSelected( !bt_checkbox.isSelected() );
                break;
            case R.id.bt_register:
//              if (!bt_checkbox.isSelected()) {
////                  showShortToast( getString( R.string.yonghuxieyiyinsizhengce ) );
//                  showFirstDialog();
//                  break;
//              }
//                intent.setClass( this, BindPhoneActivity.class );
//                intent.putExtra( "type", 2 );
//                startActivityByDefaultAnim( BindPhoneActivity.class );
                break;

            case R.id.bt_phone_login:
                startActivityByDefaultAnim( LoginByPhoneActivity.class );
                break;
        }
    }

    @Override
    protected boolean useEventBus() {
        return true;
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void Event(MsgEventEntity msg) {
        switch (msg.getMsgType()) {
            case WX_LOGIN_SUCCESS:
                helper.login( msg.getData(), this );
                showDefaultProgressDialog( true );
                break;
            case WX_LOGIN_FAILED:
                dissmissProgressDialog();
                showShortToast( msg.getData() );
                break;
        }
    }


}
